<!-- 购物车列表 -->
<template>
	<view class="list">
		<view class="list-item" v-for="(item, index) in list" :key="index" @click="handleNavTo('/pagesC-shopping/goods-detail/index')">
			<text class="checkbox iconfont" :class="{'active': !!item.checked}"
				@click.stop="handleCheckedChange(index)">
				{{!!item.checked ? '&#xe62c;': '&#xe6a6;'}}
			</text>
			<image class="pic" src="/pagesC-shopping/static/images/will-delete/13.png" mode="aspectFit"></image>
			<view class="content">
				<text class="name">舒绝杀蚁饵剂红火蚁一窝端红火舒绝杀蚁饵剂红火蚁一窝端红火</text>
				<text class="category">规格：500ml</text>
				<view class="others">
					<view class="price">
						<text class="now">￥9.9</text>
						<text class="old">￥19.9</text>
					</view>
					<view class="animate">
						<view class="options" :class="{'active': !useShoppingCart.isShowDelete}">
							<button class="minus-btn iconfont" @click.stop="">&#xe60f;</button>
							<input class="num-input" type="number" value="1" @click.stop="" />
							<button class="plus-btn iconfont" @click.stop="">&#xe60e;</button>
						</view>
						<button class="delete-btn" @click.stop=""
							:class="{'active': useShoppingCart.isShowDelete}">删除</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from "vue";
	import { useShoppingCartStore } from '../store.js';

	const useShoppingCart = useShoppingCartStore();
	const list = ref([{}, {}, {}, {}, {}, {}, {}, {}, {}, {}]);

	const handleCheckedChange = (index) => {
		list.value[index].checked = !list.value[index].checked;
	}

	const handleNavTo = (url) => {
		uni.navigateTo({
			url
		});
	}
</script>

<style lang="scss" scoped>
	.list {
		padding: 0 25rpx 20rpx;

		&-item {
			display: flex;
			align-items: center;
			height: 190rpx;
			background-color: white;
			border-radius: 20rpx;
			padding: 0 20rpx 0 18rpx;

			&+.list-item {
				margin-top: 20rpx;
			}

			.checkbox {
				flex-shrink: 0;
				font-size: 40rpx;
				color: #DCDCDC;
				margin-right: 10rpx;
			
				&.active {
					color: #FE3333;
				}
			}

			.pic {
				flex-shrink: 0;
				width: 128rpx;
				height: 128rpx;
				background-color: #F7F7F7;
				border-radius: 8rpx;
			}

			.content {
				flex-grow: 1;
				width: 0;
				height: 128rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				padding-left: 17rpx;
				overflow: hidden;

				.name {
					font-weight: 500;
					font-size: 28rpx;
					color: #222222;
					line-height: 1.5;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.category {
					font-size: 24rpx;
					color: #999999;
					line-height: 1.5;
				}

				.others {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.price {
						.now {
							font-weight: bold;
							font-size: 32rpx;
							color: #FE3333;
						}

						.old {
							font-size: 26rpx;
							color: #999999;
							text-decoration: line-through;
							margin-left: 10rpx;
						}
					}

					.animate {
						position: relative;
						height: 52rpx;
					}

					.options {
						position: absolute;
						bottom: 0;
						right: 0;
						display: flex;
						align-items: center;
						transform: translateX(100%);
						transition: transform 0.2s;

						&.active {
							transform: translateX(0);
						}

						.minus-btn {
							width: 74rpx;
							height: 56rpx;
							font-size: 18rpx;
							color: #222222;
							text-align: center;
							line-height: 56rpx;
							border: 1rpx solid #E5E5E5;
							border-right-width: 0;
							border-radius: 30rpx 0 0 30rpx;
						}

						.num-input {
							width: 60rpx;
							height: 56rpx;
							font-size: 26rpx;
							color: #222222;
							text-align: center;
							line-height: 56rpx;
							border: 1rpx solid #E5E5E5;
							box-sizing: border-box;
						}

						.plus-btn {
							width: 74rpx;
							height: 56rpx;
							font-size: 18rpx;
							color: #222222;
							text-align: center;
							line-height: 56rpx;
							border: 1rpx solid #E5E5E5;
							border-left-width: 0;
							border-radius: 0 30rpx 30rpx 0;
						}
					}

					.delete-btn {
						position: absolute;
						bottom: 0;
						right: 0;
						width: 95rpx;
						height: 52rpx;
						font-weight: bold;
						font-size: 26rpx;
						color: #FFFFFF;
						text-align: center;
						line-height: 52rpx;
						background: #FE3333;
						border-radius: 26rpx;
						transform: translateX(100%);
						transition: transform 0.2s;

						&.active {
							transform: translateX(0);
						}

						&:active {
							transform: translateX(0) scale(0.9);
						}
					}
				}
			}
		}
	}
</style>